import { ajax } from '@/utils'

const baseUrl = '/system/user'

export default {
  getUserPage(...args: IGetUserPageReq): Promise<IGetUserPageRes> {
    return ajax.post(`${baseUrl}/page`, args[0])
  },
  getUserAddFormData(): Promise<IGetUserAddFormDataRes> {
    return ajax.get(`${baseUrl}/formData/`)
  },
  getUserEditFormData(
    ...args: IGetUserEditFormDataReq
  ): Promise<IGetUserEditFormDataRes> {
    return ajax.get(`${baseUrl}/formData/${args[0]}`)
  },
  createUser(...args: ICreateUserReq): IVoidRes {
    return ajax.post(`${baseUrl}/create`, args[0])
  },
  updateUser(...args: IUpdateUserReq): IVoidRes {
    return ajax.put(`${baseUrl}/update/${args[0]}`, args[1])
  },
  deleteUser(...args: IDeleteReq): IVoidRes {
    return ajax.delete(`${baseUrl}/delete`, { data: args[0] })
  },
  exportUserPage(...args: IGetUserPageReq): IExportRes {
    return ajax.post(`${baseUrl}/page/export`, args[0], {
      responseType: 'blob'
    })
  },
  exportUserTemplate(): IExportRes {
    return ajax.post(`${baseUrl}/template/export`, null, {
      responseType: 'blob'
    })
  },
  resetPassword(...args: IResetPasswordReq): IVoidRes {
    return ajax.put(`${baseUrl}/resetPassword/${args[0]}`, args[1])
  },
  toggleUserStatus(...args: IToggleUserStatusReq): IVoidRes {
    return ajax.put(`${baseUrl}/toggleStatus/${args[0]}`)
  }
}
